<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="searchBooks/js/jquery.js"></script>
    <script src="js/jquery.dataTables.min.js"></script>
    <link rel="stylesheet" type="text/css" href="dataTableCss/jquery.dataTables.min.css"/>
    <script src="js/respond.min.js"></script>
    <script src="js/jquery.nouislider.js"></script>
    <script src="js/jquery.dataTables.min.js"></script>

    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/common.css" />
    <link rel="stylesheet" type="text/css" href="css/slide.css" />
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="css/flat-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="css/jquery.nouislider.css">

</head>
<body>

<div class="panel-body">
    <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrapno-footer ">
        <div class="row">
            <div class="col-sm-12">
                <table width="100%" class="table table-striped table-bordered table-hover dataTable no-footer dtr-inline" id="list_books" role="grid" aria-describedby="dataTables-example_info" style="width: 100%;">
                    <thead>
                    <tr>
                        <th>图书编号</th>
                        <th>书名</th>
                        <th>作者</th>
                        <th>出版社</th>
                        <th>总量</th>
                        <th>余量</th>
                    </tr>
                    </thead>
                    <tbody>

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    var href=window.location.href;
    var value = href.split('?')[1];
    var m = value.split("=")[1];
    tokenLength = location.href.length;
    tokenStart = location.href.indexOf("&");
    nameStart = location.href.lastIndexOf("?");
    name = location.href.slice(nameStart+1,tokenStart);
    token = location.href.slice(tokenStart+1,tokenLength);
    header = "bearer "+token;  //请求header头部

    $.ajax({
        type: "POST",
        headers : {"authorization":header},
        dataType: "json",
        async: true,
        url: "http://120.79.183.142/api/manageBooks/categoryDetail",
        data:{"cid": m},
        success:function (result) {
            var liuzhi_data = result["data"];
            //console.log(liuzhi_data);
            var num = liuzhi_data.length;
            for (var index2 = 0; index2 < num; index2++) {
                var irow = liuzhi_data[index2];
                var bid = irow["bid"];
                var name = irow["name"];
                var author = irow["author"];
                var publisher = irow["publisher"];
                var total_num = irow["total_num"];
                var remain_num = irow["remain_num"];

                var str = '<tr id="tr_' + bid + '">' + '<td>' + bid + '</td>' + '<td>' + name + '</td><td>' + author + '</td><td>' + publisher + '</td><td id=\"total'+bid+'\">'
                    + total_num + '</td><td id=\"remain'+bid+'\">' + remain_num + '</td>' + '</tr>';

                // console.log(str);
                $("#list_books tbody:last").append(str);
            }
            list_books();
        },
        error:function (r) {
            console.log(r);

        }
    })

    function list_books() {
        $("#list_books").DataTable({
            destroy:true,
            language: {
                "sProcessing": "处理中...",
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "表中数据为空",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                },
                "oAria": {
                    "sSortAscending": ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            }
        });
    }
</script>
</html>